<?php
namespace Popshouse\SiteBundle\Entity;

use Popshouse\SiteBundle\Entity\Pageimg;
use Popshouse\SiteBundle\Entity\Pageimage;
use Popshouse\AdminBundle\Helper\Image;

/**
 * @orm:Entity
 * @orm:Table(name="page")
 */
class Page{

	public function __construct() {
        $this->imgsSide = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
	/**
     * @orm:Id
     * @orm:Column(name="id",type="string")
     */
	protected $id;


	/**
     * @orm:Column(name="img_width",type="integer")
     * @assert:Choice(
     *     choices = { "10","15","20","25","30","35","40" }
     * )
     */
	protected $imgWidth;
	
	/**
     * @orm:Column(name="img_position",type="boolean")
     * @assert:Type("bool")
     */
	protected $imgPosition;
	

	/**
     * @orm:OneToMany(targetEntity="Pageimage", mappedBy="page", cascade={"all"})
     * @orm:OrderBy({"sort" = "ASC"})
     */
	protected $imgsSide;
	
	/**
	 * @return the $id
	 */
	public function getId() {
		return $this->id;
	}

	/**
	 * @return the $name
	 */
	public function getName() {
		return $this->getId();
	}

	/**
	 * @return the $imgWidth
	 */
	public function getImgWidth() {
		return $this->imgWidth;
	}

	/**
	 * @return the $imgPosition
	 */
	public function getImgPosition() {
		return $this->imgPosition;
	}


	/**
	 * @return the $imgSide
	 */
	public function getImgsSide() {
		return $this->imgsSide;
	}

	/**
	 * @param field_type $imgWidth
	 */
	public function setImgWidth($imgWidth) {
		$this->imgWidth = $imgWidth;
	}

	/**
	 * @param field_type $imgPosition
	 */
	public function setImgPosition($imgPosition) {
		$this->imgPosition = $imgPosition;
	}


	/**
	 * @param field_type $imgSide
	 */
	public function setImgsSide($imgsSide) {
		$this->imgsSide = $imgsSide;
	}
	

	
	public function getContentWidth(){
		return (100 - $this->getImgWidth()  - 2);
	}

	
	public function addImgSide(&$em,$img,$sort){
		/*$image = new Pageimage();
		$image->setSort($sort);
		$image->setImage($img);
		$image->setPage($this);
		$img->addOnPage($this);
		$this->getImgsSide()->add($img);
		//$em->persist($image);
		$width = round(690 * $this->getImgWidth() / 100 - 20);
		
		$pic= new Image($img->getImagePath());
	    $pic->resize($width,690);*/
		//$pic->save(PUBLIC_PATH . '/images/photo/'.$this->getName().'/'.$img->getId().'.jpg');
	}
	
	
    
}